package com.pfzy.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.snackbar.Snackbar;
import com.pfzy.ui.R;
import com.pfzy.ui.databinding.ActivitySeekbarBinding;
import com.pfzy.ui.log.MyLog;
import com.pfzy.ui.view.CountDownCircleView;
import com.pfzy.ui.view.TwoWaySeekBar;

import java.util.ArrayList;
import java.util.List;

public class SeekBarActivity extends AppCompatActivity implements View.OnClickListener {
    private ActivitySeekbarBinding mBind;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mBind = ActivitySeekbarBinding.inflate(getLayoutInflater());
        setContentView(mBind.getRoot());
        initView();
    }

    private void initView() {
        TextView title = mBind.toolbar.findViewById(R.id.layout_toolbar_title);
        title.setText("进度条");
        mBind.toolbar.findViewById(R.id.layout_toolbar_back).setOnClickListener(this);
        mBind.countdownCircle.setOnClickListener(this);

        mBind.activitySeekbarSeek1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                mBind.activitySeekbarSeek1Tv.setText("当前进度： " + i + "/10");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar开始滑动了", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar结束滑动了", Toast.LENGTH_SHORT).show();
            }
        });

        mBind.activitySeekbarSeek2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                mBind.activitySeekbarSeek2Tv.setText("当前进度： " + i + "/10");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar开始滑动了", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar结束滑动了", Toast.LENGTH_SHORT).show();
            }
        });

        mBind.activitySeekbarSeek3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                mBind.activitySeekbarSeek3Tv.setText("当前进度： " + i + "/10");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar开始滑动了", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar结束滑动了", Toast.LENGTH_SHORT).show();
            }
        });

        mBind.activitySeekbarSeek4.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                mBind.activitySeekbarSeek4Tv.setText("当前进度： " + i + "/10");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar开始滑动了", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(SeekBarActivity.this, "我seekbar结束滑动了", Toast.LENGTH_SHORT).show();
            }
        });

        List<String> data = new ArrayList<>();
        data.add("0元");
        data.add("400元");
        data.add("800元");
        data.add("1600元");
        data.add("无限");
        mBind.twoway.setData(data, new TwoWaySeekBar.OnDragFinishedListener() {
            @Override
            public void dragFinished(int leftPostion, int rightPostion) {
                Toast.makeText(SeekBarActivity.this, "回调数据Left-->" + leftPostion + "--Right-->" + rightPostion, Toast.LENGTH_SHORT).show();
                mBind.countdownCircle.startCountDown(new CountDownCircleView.OnCountDownFinishedListener() {
                    @Override
                    public void countDownStop() {
                        Toast.makeText(SeekBarActivity.this, "计时结束", Toast.LENGTH_LONG).show();
                    }
                });
            }
        });
    }

    @Override
    public void onClick(View v) {
        MyLog.logd("点击 "+v.getId());
        switch (v.getId()) {
            case R.id.layout_toolbar_back:
                finish();
                break;
            case R.id.countdown_circle:
                MyLog.logd("转圈");
                mBind.countdownCircle.startCountDown(new CountDownCircleView.OnCountDownFinishedListener() {
                    @Override
                    public void countDownStop() {
                        Toast.makeText(SeekBarActivity.this, "计时结束", Toast.LENGTH_LONG).show();
                    }
                });
                break;
            default:
                break;
        }
    }
}
